﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CMT
{
    public partial class Form2 : Form
    {
       
        public MotionPoint point { get; set; }
        public MotionPoint NowPoint { get; set; }
        public Form2(MotionPoint motionPoint,string Code)
        {
            InitializeComponent();
            textBox1.Text = motionPoint.Name;
            textBox2.Text = motionPoint.X.ToString();
            textBox3.Text = motionPoint.Y.ToString();
            textBox4.Text = motionPoint.Up_Z.ToString();
            textBox5.Text = motionPoint.Down_Z.ToString();
            textBox7.Text = motionPoint.DelayTime_Up.ToString();
            textBox8.Text = motionPoint.DelayTime_Down.ToString();
            point = motionPoint;
            if (motionPoint.IO_address == 0)
            {
                comboBox2.SelectedIndex = 0;
            }
            else
            {
                comboBox2.SelectedIndex = motionPoint.IO_address - 64;
            }
            comboBox3.SelectedIndex = (int)motionPoint.IO_state;
            switch (motionPoint.pointStyle)
            {
                case PointStyle.IOContrlo:
                    comboBox1.SelectedIndex = 0;
                    break;
                case PointStyle.KeyTest:
                    comboBox1.SelectedIndex = 1;
                    break;
                case PointStyle.Camera:
                    comboBox1.SelectedIndex = 2;
                    break;
                case PointStyle.KeyTest_IO:
                    comboBox1.SelectedIndex = 3;
                    break;
                case PointStyle.Move:
                    comboBox1.SelectedIndex = 4;
                    break;

            }

            if (motionPoint.pointStyle == PointStyle.KeyTest)
            {
                textBox6.Text = point.Code_Value; 
            }
            
            point = motionPoint;
           
        }



        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                point.Name = textBox1.Text;
                switch (comboBox1.SelectedIndex)
                {
                    case 0:
                        point.pointStyle = PointStyle.IOContrlo;
                        break;
                    case 1:
                        point.pointStyle = PointStyle.KeyTest;
                        break;
                    case 2:
                        point.pointStyle = PointStyle.Camera;
                        break;
                    case 3:
                        point.pointStyle = PointStyle.KeyTest_IO;
                        break;
                    case 4:
                        point.pointStyle = PointStyle.Move;
                        break;
                    case 5:
                        point.pointStyle = PointStyle.Wait;
                        break;
                }
                this.point.Code_Value = textBox6.Text;
                point.X = Convert.ToSingle(textBox2.Text);
                point.Y = Convert.ToSingle(textBox3.Text);
                int IO = comboBox2.SelectedIndex;
                if (IO > 16)
                {
                    point.IO_address = comboBox2.SelectedIndex;
                }
                else
                {
                    point.IO_address = comboBox2.SelectedIndex + 64;
                }
                point.IO_state = (uint)comboBox3.SelectedIndex;
                point.Up_Z = Convert.ToSingle(textBox4.Text);
                point.Down_Z = Convert.ToSingle(textBox5.Text);
                point.DelayTime_Up = Convert.ToInt16(textBox7.Text);
                point.DelayTime_Down = Convert.ToInt16(textBox8.Text);
                point.Code_Value = textBox6.Text;
                this.Hide();
            }
            catch
            {
                MessageBox.Show("写入数据异常", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                textBox2.Text = NowPoint.X.ToString();
                textBox3.Text = NowPoint.Y.ToString();
                textBox5.Text = NowPoint.Down_Z.ToString();
            }
            catch
            {
                MessageBox.Show("无效");
            }
        }

        private void textBox8_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void Form2_Load(object sender, EventArgs e)
        {
           
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Int32 a = 180;
            Int32 b = 700;
            textBox8.Text = a.ToString();
            textBox7.Text = b.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Int32 c = -473;
            textBox3.Text = c.ToString(); 
            
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Int32 d = -469;
            textBox3.Text = d.ToString();
        }


    }
}
